package com.youuvs.feignClient;

import com.youuvs.domain.User;
import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@RequestMapping("/user")
@FeignClient(value = "user-server",fallbackFactory = UserFeignFallbackFactory.class)
public interface UserFeignClient {

    @RequestMapping("/getById/{id}")
    User getById(@PathVariable("id") Long id);
}

@Component
class UserFeignFallbackFactory implements FallbackFactory<UserFeignClient>{

    @Override
    public UserFeignClient create(Throwable throwable) {
        return new UserFeignClient() {
            @Override
            public User getById(Long id) {
                return new User(-1L,"熔断了","系统错误,触发熔断!");
            }
        };
    }
}